import axios from 'axios'
axios.defaults.baseURL = 'http://localhost:8888/api/private/v1/'
    // 设置tonken值，在拦截器返回值中加入
axios.interceptors.request.use(function(config) {
    let token = localStorage.getItem('token')
    if (token) {
        config.headers.Authorization = token
    }
    return config;
}, function(error) {
    // Do something with request error
    return Promise.reject(error);
});



export const login = obj => axios.post('login', obj)
export const getlistdata = obj => axios.get('users', { params: obj })
export const addUsers = obj => axios.post('users', obj)
export const editUser = obj => axios.put(`users/${obj.id}`, obj)
export const deleteUser = id => axios.delete(`users/${id}`)
export const changeStatus = (uid, type) => axios.put(`users/${uid}/state/${type}`)
export const getRoleList = () => axios.get('roles')
export const checkRole = (id, rid) => axios.put(`users/${id}/role`, { rid: rid })
export const permissionlist = type => axios.get(`rights/${type}`)
export const deleteROlePer = (roleId, rightId) => axios.delete(`roles/${roleId}/rights/${rightId}`)
export const roleRight = (roleId, rids) => axios.post(`roles/${roleId}/rights`, { rids })
export const menus = () => axios.get('menus')
export const categories = (type, pagenum, pagesize) => axios.get('categories', { params: { type, pagenum, pagesize } })
export const addItem = obj => axios.post('categories', obj)